﻿using B.T.BasicData.ErrorCode;
using B.T.BasicData.Read.Api.DTOs;
using B.T.BasicData.Read.Api.RBACServices.IServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.T.BasicData.Read.Api.Controllers
{
    /// <summary>
    /// 用户信息控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserServices userServices;
        private readonly ILogger<UserController> logger;

        public UserController(IUserServices userServices, ILogger<UserController> logger)
        {
            this.userServices = userServices;
            this.logger = logger;
        }

        /// <summary>
        /// 分页查询用户信息及角色
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>分页用户信息</returns>
        [HttpGet]
        [Authorize]
        public async Task<ApiPaging<UserPageDto>> SraechUser([FromQuery] SraechUserDto dto)
        {
            try
            {
                return await userServices.SraechUser(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }

        }
    }
}
